package com.android1.amarena2d.test;

import com.android1.amarena2d.commons.FpsLogger;
import com.android1.amarena2d.commons.VoidFunction;
import com.android1.amarena2d.commons.Tools;
import com.android1.amarena2d.nodes.Scene;
import com.android1.amarena2d.nodes.sprites.SharedSprite;
import com.android1.amarena2d.texture.ManagedTexture;

public class SpritePerformaceTestScene extends Scene {

    final ManagedTexture tex;

    public static final int width = 720;
    public static final int height = 480;

    static SharedSprite[] sprites = new SharedSprite[50];

    public SpritePerformaceTestScene() {

        engine.getScheduler().schedule(0.5F, new FpsLogger());

        tex = engine.getTextureManager().getTexture("assets/testsprite.png");

        SharedSprite sprite;
        for (int i = 0; i < sprites.length; i++) {

            sprite = createRandomSprite();
            sprites[i] = sprite;
            add(sprite);
        }

        engine.getScheduler().schedule(new VoidFunction() {
            @Override
            public void exec() {
               updateAll();
            }
        });
    }

    public SharedSprite createRandomSprite() {

        float x = 100 + (100 * Tools.random0To1());
        float y = 100 + (100 * Tools.random0To1());
        SharedSprite s = new SharedSprite(tex, x, y);
        return s;
    }

    static void updateAll(){
        for (int i = 0; i < sprites.length; i++) {
            SharedSprite sprite = sprites[i];
            randomPos(sprite);
        }
    }

    static void randomPos(SharedSprite sprite) {
        float x = 100 + (100 * Tools.random0To1());
        float y = 100 + (100 * Tools.random0To1());
        sprite.setXY(x, y);
    }


}